package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Xwmtxxpl;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class XwmtxxplForm extends BasePage implements Serializable {
    private GenericManager<Xwmtxxpl, Long> xwmtxxplManager;
    private Xwmtxxpl xwmtxxpl = new Xwmtxxpl();
    private Long id;

    public void setXwmtxxplManager(GenericManager<Xwmtxxpl, Long> xwmtxxplManager) {
        this.xwmtxxplManager = xwmtxxplManager;
    }

    public Xwmtxxpl getXwmtxxpl() {
        return xwmtxxpl;
    }

    public void setXwmtxxpl(Xwmtxxpl xwmtxxpl) {
        this.xwmtxxpl = xwmtxxpl;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        xwmtxxplManager.remove(xwmtxxpl.getId());
        addMessage("xwmtxxpl.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            xwmtxxpl = xwmtxxplManager.get(id);
        } else {
            xwmtxxpl = new Xwmtxxpl();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (xwmtxxpl.getId() == null || xwmtxxpl.getId() == 0);
        xwmtxxplManager.save(xwmtxxpl);

        String key = (isNew) ? "xwmtxxpl.added" : "xwmtxxpl.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 